package scau.erps.view.base;

import java.awt.BorderLayout;

import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JPanel;

import scau.erps.app.Erps;
import scau.erps.entity.Research;
import scau.erps.entity.Team;
import scau.erps.service.ResearchService;
import scau.erps.service.impl.ResearchServiceImpl;

public class ResearchPanel extends JPanel {
	private static final long serialVersionUID = 1L;
	private Team team = Erps.getCurrentTeam();
	private ResearchService researchService = Erps.getIocInstance().get(
			ResearchServiceImpl.class);
	public JCheckBox crystalCheckBox,rubyCheckBox,sapphireCheckBox,districtCheckBox,domesticCheckBox,asiaCheckBox,internationCheckBox,iso9000CheckBox,iso14000CheckBox;
	public ResearchPanel(String type){		
		crystalCheckBox = new JCheckBox("Crystal");
		rubyCheckBox = new JCheckBox("Ruby");
		sapphireCheckBox = new JCheckBox("Sapphire");
		districtCheckBox = new JCheckBox("区域");
		domesticCheckBox = new JCheckBox("国内");
		asiaCheckBox = new JCheckBox("亚洲");
		internationCheckBox = new JCheckBox("国际");
		iso9000CheckBox = new JCheckBox("ISO9000");
		iso14000CheckBox = new JCheckBox("ISO14000");
		int team_Id = team.getId();						
		if (researchService.findResearchs(team_Id, "Crystal") == 4) {
			crystalCheckBox.setEnabled(false);
		}
		if (researchService.findResearchs(team_Id, "Ruby") == 6) {
			rubyCheckBox.setEnabled(false);
		}
		if (researchService.findResearchs(team_Id, "Sapphire") == 8) {
			sapphireCheckBox.setEnabled(false);
		}
		if (researchService.findResearchs(team_Id, "区域") == 1) {
			districtCheckBox.setEnabled(false);
		}
		if (researchService.findResearchs(team_Id, "国内") == 2) {
			domesticCheckBox.setEnabled(false);
		}
		if (researchService.findResearchs(team_Id, "亚洲") == 3) {
			asiaCheckBox.setEnabled(false);
		}
		if (researchService.findResearchs(team_Id, "国际") == 4) {
			internationCheckBox.setEnabled(false);
		}
		if (researchService.findResearchs(team_Id, "ISO9000") == 1) {
			iso9000CheckBox.setEnabled(false);
		}
		if (researchService.findResearchs(team_Id, "ISO14000") == 2) {
			iso14000CheckBox.setEnabled(false);
		}
		JPanel panel = new JPanel();
		if("Product".equals(type)){
			panel.add(crystalCheckBox);
			panel.add(rubyCheckBox);
			panel.add(sapphireCheckBox);
		}else if("Market".equals(type)){
			panel.add(districtCheckBox);
			panel.add(domesticCheckBox);
			panel.add(asiaCheckBox);
			panel.add(internationCheckBox);
		}else if("ISO".equals(type)){
			panel.add(iso9000CheckBox);
			panel.add(iso14000CheckBox);			
		}
		JPanel researchPanel = new JPanel(new BorderLayout());
		researchPanel.add(new JLabel("请选择需要研发的项目?"),	BorderLayout.CENTER);
		researchPanel.add(panel, BorderLayout.SOUTH);
		this.add(researchPanel);
	}
	public int getTotal(){
		int total = 0;
		if(crystalCheckBox.isSelected())
			total = total + 1;
		if (rubyCheckBox.isSelected())
			total = total + 2;
		if (sapphireCheckBox.isSelected())
			total = total + 2;
		if (districtCheckBox.isSelected()) 
			total = total + 1;
		if (domesticCheckBox.isSelected()) 
			total = total + 1;
		if (asiaCheckBox.isSelected()) 
			total = total + 1;		
		if (internationCheckBox.isSelected())
			total = total + 1;
		if (iso9000CheckBox.isSelected()) 
			total = total + 1;
		if (iso14000CheckBox.isSelected())	
			total = total + 1;		
		return total;
	}
	public void payResearchFee(){
		if (crystalCheckBox.isSelected())
			researchService.researchInvest("Crystal");
		if(rubyCheckBox.isSelected())
			researchService.researchInvest("Ruby");
		if(sapphireCheckBox.isSelected())
			researchService.researchInvest("Sapphire");
		if (districtCheckBox.isSelected())
			researchService.researchInvest("区域");
		if (domesticCheckBox.isSelected())
			researchService.researchInvest("国内");
		if (asiaCheckBox.isSelected())
			researchService.researchInvest("亚洲");
		if (internationCheckBox.isSelected())
			researchService.researchInvest("国际");
		if (iso9000CheckBox.isSelected())
			researchService.researchInvest("ISO9000");
		if (iso14000CheckBox.isSelected())
			researchService.researchInvest("ISO14000");
	}
}
